ti.rules=function(formObj){
	var passed=true;
	var msg = '';
	for (var i = 0; i < ti.rules[formObj.name].length; i++){
		var rule = ti.rules[formObj.name][i];
		if(!ti.rules.types[rule.type](formObj[rule.field],rule.p1,rule.p2,rule.p3)){
			passed = false;
			msg += rule.msg+'\n';
		}
	}
	if(!passed){
		alert('Validation error: \n---------------\n'+msg);
		return false;
	}
	return true;
}

ti.rules.types={};

ti.rules.types.length=function(obj,min,max){
	var val = new String(obj.value);
	return (val.length > min && val.length < max);
}

